﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Rotempco.Website.Logic;
using Rotempco.Core.Web.CRUD.Interfaces;
using Rotempco.Core.Web.CRUD.Events;
using Rotempco.Core.Web.Logic;

namespace Rotempco.Website.MasterPages
{
    public partial class CRUDEdit : System.Web.UI.MasterPage, ICRUDEdit
    {
        public bool RemoveBottomPanel { set { userControl_EditBottomPanel.Visible = !value; } }
        public event SaveEvent SaveEvent;

        protected void Page_Load(object sender, EventArgs e)
        {
            long? id = UrlLogic.GetIdFromUrl();

            if (id.HasValue == true)
            {
                literal_BreadCrumb.Text = "&gt Edit";
            }
            else
            {
                literal_BreadCrumb.Text = "&gt New";
            }
            
        }

        public void SetErrorMessage(string errorMessage)
        {
            userControl_EditBottomPanel.SetErrorMessage(errorMessage);
        }

        public void SetReturnUrl(string url)
        {
            userControl_EditBottomPanel.ReturnUrl = url;
        }

        protected bool userControl_EditBottomPanel_OnSaveEvent()
        {
            return SaveEvent();
        }
    }
}